/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * The login function
 * That function submit the login form  
 */

function login () {
    $('#form_13').submit();
}


/**
 * Notifications global variable
 */
var nclicks = 0;

/**
 * Avancement setting
 */
$(document).ready(function (){
    // Set the tache ID
    $('.set-avancement').click(function (){
        $('#header-text').text('Niveau actuel : ' + $(this).attr('current') + '%' + '  -  Date de fin : ' + $(this).attr('dfin'));
        $('#task-name').text($(this).attr('task'));
        $('#tid').attr('value', $(this).attr("id"));
    })
    
    // submit the setting request
    $('#save-avancement').click(function (){
        $('#edit-avancement-form').submit();
    })
    
    // The logout function
    /**
     * While logginout the notifications are clean
     */
    $('#logout').click(function (){
        var url = 'logout';
        $.ajax({
            url : url,
            cache : false,
            success : function (text){
                
            }
        })
    })
    
    /**
     * Clear notifications
     */
    $('#vide-notifications').click(function(){
        $(".panel").toggle("hide");
        $('#notifs').text(0);
        
        // Dalete AJAX
        $.ajax({
            url : 'delete-notifs',
            cache : false,
            success : function (){
                
            },
            error : function (){
                
            }
        })
    })
    
    $('.trigger').click(function(){
        nclicks ++;
        var n = $('#notifs').text();
        if (n != 0) {
            $(".panel").toggle("slow");
            //$(this).toggleClass("active");
            //if ( nclicks >= 2) $('#notifs').text(0);
        }
        return false;
    })
    
    /**
     * Create a discussion
     */
    $('#save-discussion').click(function (){
        $('#create-discussion-form').submit();
    })
    
    // projet details ajax
    $('.get-deails').click(function (){
        var pid = $(this).attr('pid');
        $.ajax({
            url : 'details?pid=' + pid,
            cache : false,
            success : function (html) {
               $('#body').html(html);
            },
            error : function (){
                alert ( ' Error ! ');
            }
        })
    })
    
    // task details ajax
    $('.get-task-deails').click(function (){
        var tid = $(this).attr('tid');
        $.ajax({
            url : 'task-details?tid=' + tid,
            cache : false,
            success : function (html) {
               $('#body').html(html);
            },
            error : function (){
                alert ( ' Error ! ');
            }
        })
    })
})